using System;
using System.Collections.Generic;

using IBatisNet.DataMapper;

using log4net;

using GymManager.Exception;
using GymManager.Persistence.VO;

namespace GymManager.Persistence.DAO
{
    /// <summary>
    /// Class responsible by getting information from database about permission
    /// </summary>
    public class PermissionDAO
    {
        // logger instance
        private ILog _logManager = LogManager.GetLogger(typeof(PermissionDAO));

        /// <summary>
        /// Method responsible by getting all permission in according to a filter
        /// </summary>
        /// <param name="Permission">permission vo filter</param>
        /// <returns>List of all avaliable permissions matching with the given criteria</returns>
        public IList<Permission> findByAny(Permission permissionVO)
        {
            if (_logManager.IsInfoEnabled)
            {
                _logManager.Info("Begin Method");
            }

            // list of permissions to be returned
            IList<Permission> permissionList = null;

            try
            {
                ISqlMapper ibatisMapper = DAOManager.getInstance();
                permissionList = ibatisMapper.QueryForList<Permission>("Permission.findByAny", permissionVO);
            }
            catch (System.Exception ex)
            {
                _logManager.Error("Error while retrieving permission information", ex);
                throw new PersistenceException("Error while retrieving permission information", ex);
            }

            if (_logManager.IsInfoEnabled)
            {
                _logManager.Info("End Method");
            }

            return permissionList;
        }
    }
}
